<template>
  <div class="bd">
      <div class="js">
        选择角色： <select v-model="user.type" class="xl">
          <option value="1">法师</option>
          <option value="2">打野</option>
        </select>
      </div>
      <div><van-field class="sr" v-model="user.phone" placeholder="请输入手机号" /> </div>
      <div><van-field class="sr" v-model="user.password" center clearable placeholder="请输入验证码">
      <template #button>
        <van-button size="small" type="primary">发送验证码</van-button>
      </template>
          </van-field>
      </div>
      <!-- <button @click="login">登录</button> -->
      <div class="btn">
        <van-button type="primary" @click="login">登录</van-button>
        <van-button type="info" to="/register">注册</van-button>
      </div>
  </div>
</template>

<script>
import {reqLogin} from "../../http/http"
import {Toast} from 'vant';
export default {
  data(){
    return {
       type:"",//角色
      user:{
        name:"admin",//账号，
        pass:"123",//密码
      }
    }
  },
  methods:{
    login(){
      if(this.user.type===""){
        alert("请选择角色")
        return;
      }
      //验证账号和密码
      reqLogin(this.user).then(res=>{
        // console.log(res);
        if(res.data.code==200){
          //成功
          // 1.存用户信息
          localStorage.setItem("user",JSON.stringify(res.data.list))
          // 2.存登录状态
          localStorage.setItem("isLogin","true")
          // 3.存用户角色
           localStorage.setItem("type",this.type)
          // 4.跳转页面
          this.$router.push("/index/home")
        }else{
          alert(res.data.msg)
        }
      })
    }
  }
}
</script>

<style scoped>
.bd{
  /* margin-top:2rem; */
}
.js{
  margin: 0.2rem;
  width: 100vw;
  text-align: center;
}
.js .xl{
  width: 3rem;
  height: 0.6rem;
}
.sr{
  border-bottom: #666 solid 0.01rem;
  margin: 0.1rem;
}
.btn{
  width: 100vw;
  text-align: center;
}
</style>